{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 10,
   "id": "2beca63d",
   "metadata": {},
   "outputs": [],
   "source": [
    "import tensorflow as tf\n",
    "import pandas as pd \n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "id": "f88a581a",
   "metadata": {},
   "outputs": [],
   "source": [
    "fashion_mnist=tf.keras.datasets.fashion_mnist.load_data()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "48f7040b",
   "metadata": {},
   "outputs": [],
   "source": [
    "(train_image, train_label),(test_image,test_label)=fashion_mnist"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "id": "226923a9",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "((60000, 28, 28), (60000,), (10000, 28, 28), (10000,))"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "train_image.shape, train_label.shape,test_image.shape,test_label.shape"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "id": "5f8b6048",
   "metadata": {},
   "outputs": [],
   "source": [
    "train_image=train_image/255.0\n",
    "test_image=test_image/255.0"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "id": "c6f83164",
   "metadata": {},
   "outputs": [],
   "source": [
    "input= tf.keras.Input((28,28))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "id": "baa81d24",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=tf.keras.layers.Flatten()(input)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "e67be57a",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=tf.keras.layers.Dense(32,activation='relu')(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "id": "840a74af",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=tf.keras.layers.Dropout(0.5)(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "id": "b212b539",
   "metadata": {},
   "outputs": [],
   "source": [
    "x=tf.keras.layers.Dense(64,activation='relu')(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "id": "cccae267",
   "metadata": {},
   "outputs": [],
   "source": [
    "output=tf.keras.layers.Dense(10,activation='softmax')(x)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "id": "2bcbf699",
   "metadata": {},
   "outputs": [],
   "source": [
    "model=tf.keras.Model(inputs=input,outputs=output)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "id": "7cf6f676",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Model: \"model\"\n",
      "_________________________________________________________________\n",
      "Layer (type)                 Output Shape              Param #   \n",
      "=================================================================\n",
      "input_1 (InputLayer)         [(None, 28, 28)]          0         \n",
      "_________________________________________________________________\n",
      "flatten (Flatten)            (None, 784)               0         \n",
      "_________________________________________________________________\n",
      "dense (Dense)                (None, 32)                25120     \n",
      "_________________________________________________________________\n",
      "dropout (Dropout)            (None, 32)                0         \n",
      "_________________________________________________________________\n",
      "dense_1 (Dense)              (None, 64)                2112      \n",
      "_________________________________________________________________\n",
      "dense_2 (Dense)              (None, 10)                650       \n",
      "=================================================================\n",
      "Total params: 27,882\n",
      "Trainable params: 27,882\n",
      "Non-trainable params: 0\n",
      "_________________________________________________________________\n"
     ]
    }
   ],
   "source": [
    "model.summary()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "id": "b53d49b4",
   "metadata": {},
   "outputs": [],
   "source": [
    "model.compile(loss=\"sparse_categorical_crossentropy\",\n",
    "             optimizer='adam',\n",
    "             metrics=['acc'])"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "id": "7042c08e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Epoch 1/20\n",
      "1875/1875 [==============================] - 4s 2ms/step - loss: 1.0987 - acc: 0.5886 - val_loss: 0.5255 - val_acc: 0.8128\n",
      "Epoch 2/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.6710 - acc: 0.7515 - val_loss: 0.5343 - val_acc: 0.8098\n",
      "Epoch 3/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.6172 - acc: 0.7730 - val_loss: 0.5022 - val_acc: 0.8266\n",
      "Epoch 4/20\n",
      "1875/1875 [==============================] - 3s 1ms/step - loss: 0.5849 - acc: 0.7864 - val_loss: 0.5578 - val_acc: 0.7883\n",
      "Epoch 5/20\n",
      "1875/1875 [==============================] - 3s 1ms/step - loss: 0.5602 - acc: 0.7946 - val_loss: 0.5787 - val_acc: 0.7641\n",
      "Epoch 6/20\n",
      "1875/1875 [==============================] - 3s 1ms/step - loss: 0.5582 - acc: 0.7941 - val_loss: 0.5436 - val_acc: 0.7942\n",
      "Epoch 7/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.5373 - acc: 0.8052 - val_loss: 0.5126 - val_acc: 0.8199\n",
      "Epoch 8/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.5255 - acc: 0.8100 - val_loss: 0.5860 - val_acc: 0.7655\n",
      "Epoch 9/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.5234 - acc: 0.8101 - val_loss: 0.5472 - val_acc: 0.7928\n",
      "Epoch 10/20\n",
      "1875/1875 [==============================] - 3s 1ms/step - loss: 0.5230 - acc: 0.8084 - val_loss: 0.5375 - val_acc: 0.8034\n",
      "Epoch 11/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.5207 - acc: 0.8107 - val_loss: 0.5584 - val_acc: 0.7818\n",
      "Epoch 12/20\n",
      "1875/1875 [==============================] - 4s 2ms/step - loss: 0.5046 - acc: 0.8153 - val_loss: 0.5127 - val_acc: 0.8111\n",
      "Epoch 13/20\n",
      "1875/1875 [==============================] - 5s 2ms/step - loss: 0.5105 - acc: 0.8128 - val_loss: 0.5015 - val_acc: 0.8184\n",
      "Epoch 14/20\n",
      "1875/1875 [==============================] - 3s 1ms/step - loss: 0.5051 - acc: 0.8162 - val_loss: 0.5605 - val_acc: 0.7890\n",
      "Epoch 15/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.5034 - acc: 0.8174 - val_loss: 0.5645 - val_acc: 0.7838\n",
      "Epoch 16/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.4864 - acc: 0.8212 - val_loss: 0.5073 - val_acc: 0.8075\n",
      "Epoch 17/20\n",
      "1875/1875 [==============================] - 3s 1ms/step - loss: 0.4863 - acc: 0.8233 - val_loss: 0.5104 - val_acc: 0.8195\n",
      "Epoch 18/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.4901 - acc: 0.8207 - val_loss: 0.5094 - val_acc: 0.8142\n",
      "Epoch 19/20\n",
      "1875/1875 [==============================] - 3s 2ms/step - loss: 0.4801 - acc: 0.8228 - val_loss: 0.5054 - val_acc: 0.8177\n",
      "Epoch 20/20\n",
      "1875/1875 [==============================] - 3s 1ms/step - loss: 0.4746 - acc: 0.8258 - val_loss: 0.4918 - val_acc: 0.8302\n"
     ]
    }
   ],
   "source": [
    "history=model.fit(train_image ,train_label,epochs=20,\n",
    "         validation_data=(test_image,test_label)\n",
    "         )"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "963b545b",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.8.8"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
